<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SQDatabaseE.aspx.vb" Inherits="DatabaseE" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">    
    <link href="ADStyles.css" rel="stylesheet" type="text/css" />
</head>

<script type="text/javascript" language="javascript">
    function RefreshServerList()
    {
        var TopWindow=top.window.document;
        var DashFrame=TopWindow.getElementById('Menu');
        DashFrame.src='SQServerL.aspx';
                
        var Refresh=document.getElementById('hidRefreshParent');

        if (Refresh.value=='yes')
        {        
            var BodyFrame=TopWindow.getElementById('Body');
            BodyFrame.src='SQDatabaseE.aspx?S=<%=me.ServerID%>&D=<%=me.DatabaseID%>&DV=<%=me.DatabaseRevID %>';
        }

        Refresh.value='no';
        
        return true;
    }

    function ClearDatabase()
    {
        var TopWindow=top.window.document;
        var RDatabase=TopWindow.getElementById('DID');
        
        RDatabase.value='';
        
        var DashFrame=TopWindow.getElementById('Menu');
        DashFrame.src='SQServerL.aspx';
        
        setToolbarAction('Delete');
        
        return true;
    }

    function setToolbarAction(varAction)
    {
        var oAction=document.getElementById("hidToolbarAction");
        oAction.value=varAction;

        return true;
    }
    
    function setMaster()
    {
        var TopWindow=top.window.document;
        
        var DashTitle=TopWindow.getElementById('DashboardTitle');
        var DashMode=TopWindow.getElementById('DMode');

        var RServer=TopWindow.getElementById('SID');
        var RDatabase=TopWindow.getElementById('DID');

        var LServer=document.getElementById('SID');
        var LDatabase=document.getElementById('DID');
                        
        if (DashTitle!=null) DashTitle.innerHTML='<%=me.FormLabel %>';
        if (DashMode!=null) DashMode.value='<%=me.EditMode %>';
 
        if ( 
                (RServer.value>'' && LServer.value=='')
                && (RDatabase.value>'' && LDatabase.value=='')
           )
        {
            LServer.value=RServer.value;
            LDatabase.value=RDatabase.value;
            document.form1.submit();
        }
        else
        {          
            RServer.value=LServer.value;
            RDatabase.value=LDatabase.value;
        }
    }
    
    function onLoad()
    {        
        setMaster();
        
        var DID=document.getElementById('DID');
        
        if (DID.value.length==0)
        {
            SetEdit('1');
        }
        
        var RefreshParent=document.getElementById('hidRefreshParent');
        if (RefreshParent.value=='yes')
            RefreshServerList();
        
        return true;
    }
    
    function SetEdit(varMode)
    {
        var CPanel=document.getElementById('divCString');
        var SPanel=document.getElementById('divScanSchedule');
        
        CPanel.style.top='170px';
        SPanel.style.top='170px';
        
        if (varMode=='1')
            if (CPanel.style.visibility=='hidden')
            {
                CPanel.style.visibility='visible';
                SPanel.style.visibility='hidden';
            }
            else
            {
                CPanel.style.visibility='hidden';
                SPanel.style.visibility='visible';
                SetType('');
            }
        else
        {
            CPanel.style.visibility='hidden';
            SPanel.style.visibility='visible';
        }
        
        return true;
    }
    
    function SetType(varMode)
    {   
        var ckStandard=document.getElementById('rdStandard');
        var ckTrusted=document.getElementById('rdTrusted');
        var ckFile=document.getElementById('rdFile');
        var ckIP=document.getElementById('rdIP');
                
        var MyUInfo=document.getElementById('divPermissions');
        var MyPort=document.getElementById('divPort');
        var MyLibrary=document.getElementById('divLibrary');
        var MyFile=document.getElementById('divFile');
        
        var cmdButton=document.getElementById('cmdSaveConnectionString');
        
        //cmdButton.style.visibility='visible';
        
        switch (varMode)
        {
            //Standard
            case 'S':         
                ckStandard.checked=true;
            
                MyUInfo.style.visibility='visible';
                MyUInfo.style.top='70px';
                
                MyLibrary.style.visibility='visible';
                MyLibrary.style.top='130px';
                
                MyPort.style.visibility='hidden';
                MyFile.style.visibility='hidden';
                
                break;
                
            //Integrated
            case 'I': 
                ckTrusted.checked=true;
                
                MyLibrary.style.visibility='visible';
                MyLibrary.style.top='70px';
                
                MyUInfo.style.visibility='hidden';
                MyPort.style.visibility='hidden';
                MyFile.style.visibility='hidden';
                
                break;
                
            //File
            case 'F':
                ckFile.checked=true;
                
                MyFile.style.visibility='visible';
                MyFile.style.top='70px';
 
                MyLibrary.style.visibility='hidden';
                MyUInfo.style.visibility='hidden';
                MyPort.style.visibility='hidden';
                
                break;
                               
            //TCP/IP
            case 'T':    
                ckIP.checked=true;
                            
                MyPort.style.visibility='visible';
                MyPort.style.top='70px';
                
                MyLibrary.style.visibility='hidden';
                MyUInfo.style.visibility='hidden';
                MyFile.style.visibility='hidden';
                
                break;
            
            default:
                ckStandard.checked=false;
                ckTrusted.checked=false;
                ckFile.checked=false;
                ckIP.checked=false;
                
                MyPort.style.visibility='hidden';            
                MyLibrary.style.visibility='hidden';
                MyUInfo.style.visibility='hidden';
                MyFile.style.visibility='hidden';   
        }
        
        return true;
    }
</script>

<body onload="onLoad();">
    <form id="form1" runat="server">
    <div>
        <input type="hidden" id="SID" runat="server" />
        <input type="hidden" id="DID" runat="server" />
        
        <table style="width: 490px; height:475px; border: solid 1px black; border-collapse:collapse;">
        <tr>
             <td style="width: 490px; vertical-align:top; text-align:left; height:20px;">
             
                <table width="100%" style="border-collapse:collapse;">
                    <tr class="wmObjectDetailDev_TH" style="height: 30px; border-collapse: collapse; background-color: #C3C4C1; border-bottom: solid 1px black;">
                        <td style="width:300px; font-weight: bold; padding-left: 5px;">
                            SQLAutoDoc Add/Edit Database
                        </td>
                        <td style="width:20px;">                
                            <input type="image"
                                   src="images/tb_del.jpg"
                                   id="cmdRemove"
                                   name="cmdRemove"
                                   title="Remove Database"
                                   alt="Remove Database"
                                   onclick="ClearDatabase();"
                                   value="Remove Database"/>
                        </td>
                        <td style="width:20px;">
                            <input type="image"
                                   src="images/tb_save.jpg"
                                   id="cmdUpdate"
                                   name="cmdUpdate"
                                   title="Update Database Info"
                                   alt="Update Database"
                                   onclick="setToolbarAction('Update');"
                                   value="Update Database Info"/>
                        </td>
                        <td style="width:20px;">
                            <input type="image"
                                   src="images/tb_xml.jpg"
                                   id="cmdXML"
                                   name="cmdXML"
                                   title="View Database as XML"
                                   alt="View Database"
                                   onclick="setToolbarAction('XML');"
                                   value="View Database as XML"/>
                        </td>
                        <td style="width:20px;">
                            <input type="image"
                                   src="images/tb_scan.jpg"
                                   id="cmdScan"
                                   name="cmdScan"
                                   title="Scan database now"
                                   alt="Scan database now"
                                   onclick="setToolbarAction('Scan');"
                                   value="Scan database now"/>
                        </td>
                        <td style="width: 130px;">
                            <select id="DBREVID"    
                                    name="DBREVID"
                                    runat="server"
                                    style="width: 120px;"/>                          
                        </td>
                    </tr>
                </table>
                
            </td>
        </tr>
        
        <tr style="height: 70px;">
            <td style="vertical-align:top; text-align:left; style="height: 70px;">

            <table style="height: 70px;">
                <tr>
                    <td>Server Name:</td>
                    <td>
                        <asp:Label ID="lblServerName" runat="server"></asp:Label>
                    </td>
                </tr>
                
                <tr>
                    <td>Database Name:</td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                        <div id="errName" visible="false" class="wmErrorMessage" runat="server">No Error</div>
                    </td>
                </tr>
                
                <tr>
                    <td>Description:</td>
                    <td>
                        <asp:TextBox ID="txtDesc" runat="server" Width="360px"></asp:TextBox>
                        <div id="Div1" visible="false" class="wmErrorMessage" runat="server">No Error</div>
                    </td>
                </tr>
                
                <tr>
                    <td>Is Active:</td>
                    <td>
                        <asp:checkbox ID="chkIsActive" runat="server" Checked></asp:checkbox>
                        <div id="Div2" visible="false" class="wmErrorMessage" runat="server">No Error</div>
                    </td>
                </tr>
                
                <tr id="trCS" runat="server">
                    <td>Connection String:</td>
                    <td>
                        <input id="cmdSet" name="cmdSet" type="button" value="Set" class="btn2" onclick="SetEdit(1);" />                 
                    </td>
                </tr>
            </table>
            
            </td>
        </tr>
    
        <tr>
            <td colspan="2" style="height: 400px;">&nbsp;</td>
        </tr>
    </table>
</div>

<div id="errCString" visible="false" class="wmErrorMessage" runat="server" style="position:absolute; top: 125px; left: 230px; width: 260px;">
No Error
</div>  

<div id="divScanSchedule" style="visibility: visible; border: solid 1px black; border-collapse: collapse; height:215px; width:435px; padding-left: 20px; padding-top: 10px; margin-top:20px; margin-left: 15px; left: 8px; position:absolute; top: 170px;">
    <div id="divTitle2" style="text-align:center; border: solid 1px black; background-color:LightGrey; width: 415px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; margin-bottom: 10px;">
        Scan Configuration Settings
    </div>
    
    <table style="width:415px; border: solid 1px black; border-collapse: collapse;">           
        <tr>
            <td style="width:100px; border-bottom:solid 1px black; text-align:center; vertical-align:bottom;">Type</td>
            <td style="width:60px; border-bottom:solid 1px black; text-align:center; vertical-align:bottom;">Interval (minutes)</td>
            <td style="width:155px; border-bottom:solid 1px black; text-align:center; vertical-align:bottom;">Last Scan</td>
            <td style="width:100px; border-bottom:solid 1px black; text-align:center; vertical-align:bottom;">Email Report</td>
        </tr>    
        
        <tr style="height: 30px; vertical-align:bottom;">
            <td style="text-align:right; padding-right: 10px; padding-top:5px;">SizeScan</td>
            <td style="padding-top:5px;">
            <input type="text" id="txtSizeScanInterval" size="5" maxlength="4" runat="server" />
            <div id="errSizeScan" visible="false" class="wmErrorMessage" runat="server">No Error</div> 
            </td>
            <td style="padding-left: 25px; padding-top:5px;"><div id="lblLastSizeScan" runat="server">Not Scanned</div></td>
            <td style="vertical-align:top;"><input type="checkbox" runat="server" id="SizeScanReport" />Send Report</td>
        </tr>
        
        <tr style="height: 25px; vertical-align:bottom;">
            <td style="text-align:right; padding-right: 10px;">BlockScan</td>
            <td>
            <input type="text" id="txtBlockScanInterval" size="5" maxlength="4" runat="server" />
            <div id="errBlockScan" visible="false" class="wmErrorMessage" runat="server">No Error</div> 
            </td>
            <td style="padding-left: 25px;"><div id="lblLastBlockScan" runat="server">Not Scanned</div></td>
            <td style="vertical-align:top;"><input type="checkbox" runat="server" id="BlockScanReport" />Send Report</td>
        </tr>
        
        <tr style="height: 25px; vertical-align:bottom;">
            <td style="text-align:right; padding-right: 10px;">ConnectionScan</td>
            <td>
            <input type="text" id="txtConnectionScanInterval" size="5" maxlength="4" runat="server" />
            <div id="errConnectionScan" visible="false" class="wmErrorMessage" runat="server">No Error</div> 
            </td>
            <td style="padding-left: 25px;"><div id="lblLastConnectionScan" runat="server">Not Scanned</div></td>
            <td style="vertical-align:top;"><input type="checkbox" runat="server" id="ConnectionScanReport" />Send Report</td>
        </tr>
        
        <tr style="height: 25px; vertical-align:bottom; ">
            <td style="text-align:right; padding-right: 10px;">WaitStateScan</td>
            <td>
            <input type="text" id="txtWaitStateScanInterval" size="5" maxlength="4" runat="server" />
            <div id="errWaitStateScan" visible="false" class="wmErrorMessage" runat="server">No Error</div> 
            </td>
            <td style="padding-left: 25px;"><div id="lblLastStateScan" runat="server">Not Scanned</div></td>
            <td style="vertical-align:top;"><input type="checkbox" runat="server" id="WaitScanReport" />Send Report</td>
        </tr>
        
        <tr style="height: 25px; vertical-align:bottom;">
            <td style="text-align:right; padding-right: 10px; padding-bottom: 5px;">SchemaScan</td>
            <td style="padding-bottom: 5px;">
            <input type="text" id="txtSchemaScanInterval" size="5" maxlength="4" runat="server"/>
            <div id="errSchemaScan" visible="false" class="wmErrorMessage" runat="server">No Error</div> 
            </td>
            <td style="padding-left: 25px;padding-bottom: 5px;"><div id="lblLastSchemaScan" runat="server">Not Scanned</div></td>
            <td style="vertical-align:top;"><input type="checkbox" runat="server" id="SchemaScanReport" />Send Report</td>
        </tr>
    </table>
</div>

<div id="divCString" style="visibility: hidden; border: solid 1px black; border-collapse: collapse; height:175px; width:435px; padding-left: 20px; padding-top: 10px; margin-top:20px; margin-left: 15px; position:absolute; top: 170px;">

    <div id="divTitle1" style="text-align:center; border: solid 1px black; background-color:LightGrey; width: 415px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; margin-bottom: 10px;">
        Set SQL Server Connection
    </div>
    
    <table>           
        <tr>
            <td>Type</td>
            <td style="width: 414px">
                <input type="radio"
                       runat="server"
                       id="rdStandard"
                       name="grpType" 
                       style="width: 24px;" 
                       value="Standard" 
                       onclick ="SetType('S');" />
                Standard
                       
                <input type="radio"
                       runat="server"
                       id="rdTrusted"
                       name="grpType" 
                       style="width: 24px;" 
                       value="Trusted" 
                       onclick ="SetType('I');" />
                Trusted

                <input type="radio"
                       runat="server"
                       id="rdFile"
                       name="grpType"  
                       style="width: 24px;" 
                       value="IP" 
                       onclick ="SetType('F');" />
                FileName 
                                       
                <input type="radio"
                       runat="server"
                       id="rdIP"
                       name="grpType"  
                       style="width: 24px;" 
                       value="IP" 
                       onclick ="SetType('T');" />
                TCP/IP       
            </td>
        </tr>
    </table>

    <div id="divPermissions" style="visibility:hidden; position:absolute;">
    <table>
        <tr id="trUserID" runat="server">
            <td>User ID</td>
            <td style="width: 314px">
                <input type="text"  
                       runat="server"
                       id="txtUserName"
                       name="txtName"
                       style="width: 100px;" />        
            </td>
        </tr>
        
        <tr id="trPassword" runat="server">
            <td>Password</td>
            <td style="width: 314px">
                <input type="password"
                       runat="server"
                       id="txtPassword"
                       name="txtPassword"
                       style="width: 100px;" />        
            </td>
        </tr>
    </table>
    </div>

    <div id="divFile"  style="visibility:hidden; position:absolute;">
    <table>
        <tr>
            <td colspan="2" valign="top">
            <b>File Connections require SQL Server 2005</b>
            </td>           
        </tr>
                
        <tr>
            <td>FileName</td>
            <td style="width: 314px">
                <input type="text"
                       runat="server"
                       id="txtFile"
                       name="txtFile"
                       style="width: 270px;" />                      
            </td>                           
        </tr>
        <tr>
            <td colspan="2" valign="top">
                <input type="checkbox"
                       runat="server"
                       id="chkUserInstance"
                       name="chkUserInstance"
                       checked />  
                       
                Connect via User Instance (local 2005 express only)                    
            </td>           
        </tr>
    </table>
    </div>
    
    <div id="divPort"  style="visibility:hidden; position:absolute;">
    <table>
        <tr>
            <td>IP Address</td>
            <td style="width: 314px">
                <input type="text"
                       runat="server"
                       id="IP1"
                       name="txtIP1"
                       style="width: 38px;" />  
                       
                <input type="text"
                       runat="server"
                       id="IP2"
                       name="txtIP2"
                       style="width: 38px;" />  
                       
                 <input type="text"
                       runat="server"
                       id="IP3"
                       name="txtIP3"
                       style="width: 38px;" />       
                       
                 <input type="text"
                       runat="server"
                       id="IP4"
                       name="txtIP4"
                       style="width: 38px;" />                                         
            </td>           
        </tr>

        <tr>
            <td>Port</td>
            <td style="width: 314px">
                <input type="text"
                       runat="server"
                       id="txtPort"
                       name="txtPort"
                       value="1433"
                       style="width: 48px;" />  
            </td>           
        </tr>
    </table>
    </div>

    <div id="divLibrary" style="visibility:hidden; position:absolute;">
    <table>    
        <tr id="trLibrary" runat="server">
            <td>Network Library (TCP/IP or named pipes)</td>
            <td>
               <input type="radio"
                       runat="server"
                       id="rdNamedPipes"
                       name="grpNL"  
                       style="width: 24px;" 
                       value="NP" />
              Named Pipes
              
              <input type="radio"
                       runat="server"
                       id="rdTCPIP"
                       name="grpNL"  
                       style="width: 24px;" 
                       checked
                       value="TCP" />
              TCP/IP
           </td>
        </tr>
    </table>
    </div>  
    
    <input type="submit" runat="server" id="cmdSaveConnectionString" value="Save Connection String" style="position:relative; top:100px; visibility:hidden;" /> 


    <input type="hidden" id="hidNC" runat="server" />
    <input type="hidden" id="hidEC" runat="server" />
    <input type="hidden" id="hidToolbarAction" runat="server" />
    <input type="hidden" id="hidRefreshParent" value="no" runat="server" />
</div>
    </form>
</body>
</html>
